<script type="text/javascript" src="<?php echo base_url("public/template/backend/plugins/ckeditor/ckeditor.js")?>"></script>
<script>
    $(function() {
        if(CKEDITOR.instances['data[des]']) {
            CKEDITOR.remove(CKEDITOR.instances['txt_content']); 
        } 
        CKEDITOR.config.width = 600;
        CKEDITOR.config.height = 150;
        CKEDITOR.replace('data[des]', {});
    })
</script>

<?php 
            $re = "/add/";
$str = uri_string();
if (preg_match($re, $str)) {
    $sub = TRUE;
} else {
    $sub = FALSE;
}
?>
<div class="title-menu">
    <h2><?php if($sub==TRUE) echo "Thêm sản phẩm"; else echo "Sửa sản phẩm";?></h2>
</div>
<nav class="bonus">
    <a href="<?php echo base_url("backend/products");?>"><< Quay lại</a>
</nav>
<article>
    <form method="post" action="" enctype="multipart/form-data">
        <fieldset>
            <ul class="error">
                <?php echo validation_errors(); ?>
                <?php echo isset($error)?$error:'';?>
            </ul>            
            <p>
                <label>Tên sản phẩm:</label>
                <input type="text" name="data[name]" value="<?php if(isset($pro->name)) echo $pro->name; else echo set_value('data[name]');?>"/>
            </p>
            <p>
                <label>Giá sản phẩm:</label>
                <input type="text" name="data[price]" value="<?php if(isset($pro->price)) echo $pro->price; else echo set_value('data[price]');?>"/>
            </p>
            <p>
                <label>Hình ảnh:</label>
                <?php if (isset($pro->img)) { ?>
                <img src="<?php echo base_url($pro->img); ?>" width="100" height="100" alt="No Image"/>
            <?php } ?>
                <input type="file" name="img"/>
            </p>
            <p>
                <label>Mô tả:</label>
                <textarea name="data[des]" id="data[des]"><?php if(isset($pro->des)) echo $pro->des; else echo set_value('data[des]');?></textarea>
            </p>
            <p>
                <label>Kích thước:</label>
                <input type="text" name="data[size]" value="<?php if(isset($pro->size)) echo $pro->size; else echo set_value('data[size]');?>"/>
            </p>
            <p>
                <label>Cat ID:</label>
                <select name="data[cid]">
                    <?php
                    if (isset($parcat) && count($parcat))
                        foreach ($parcat as $pcat) {
                            ?>
                            <option value="<?php echo $pcat->id;?>"><?php echo $pcat->name;?></option>
                            <?php
                            $chilcat = $this->mcategories->getChildCat($pcat->id);
                            if (isset($chilcat) && count($chilcat))
                                foreach ($chilcat as $ccat) {
                                    ?>
                                    <option value="<?php echo $ccat->id;?>"
                                            <?php
                                                            if (isset($pro->cid) && $pro->cid != 0) {
                                                                if ($pro->cid === $ccat->id)
                                                                    echo 'selected';
                                                            }
                                                            ?>
                                            >---<?php echo $ccat->name;?></option>
                                    <?php
                                }
                        }
                    ?>
                </select>
            </p>
            <p>
                <label>Số lượng:</label>
                <input type="text" name="data[qty]" value="<?php if(isset($pro->qty)) echo $pro->qty; else echo set_value('data[qty]');?>"/>
            </p>
            <p>
                <label>Trạng thái:</label>
                <select name="data[status]">
                    <option value="1" <?php if(isset($pro->status) && $pro->status == 1) echo "selected";?>>Còn hàng</option>
                    <option value="0" <?php if(isset($pro->status) && $pro->status == 0) echo "selected";?>>Hết hàng</option>                    
                </select>
            </p>
            <p>
                <label></label>
                <input type="submit" name="add" value="<?php if($sub == TRUE)echo "Thêm"; else echo "Sửa";?>"/>
            </p>
        </fieldset>
    </form>
</article>